from flask import Flask
from app.config import Config
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager

db = SQLAlchemy()
migrate = Migrate()
login = LoginManager()
login.login_view = 'auth.login'

def create_app(config_class=Config):

    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)

    login.init_app(app)

    from app.backend import bp as backendbp
    app.register_blueprint(backendbp, url_prefix='/backend')

    from app.auth import bp as authbp
    app.register_blueprint(authbp, url_prefix='/auth')

    return app
